﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Middle_641_MyCircularDeque
{
    class MainProject
    {
        static void Main(string[] args)
        {
            //MyCircularDeque circularDeque = new MyCircularDeque(3); // 设置容量大小为3
            //circularDeque.InsertLast(1);                    // 返回 true
            //circularDeque.InsertLast(2);                    // 返回 true
            //circularDeque.InsertFront(3);                   // 返回 true
            //circularDeque.InsertFront(4);                   // 已经满了，返回 false
            //circularDeque.GetRear();                // 返回 2
            //circularDeque.IsFull();                     // 返回 true
            //circularDeque.DeleteLast();                 // 返回 true
            //circularDeque.InsertFront(4);                   // 返回 true
            //circularDeque.GetFront();               // 返回 4

            //Console.WriteLine(TimeRequiredToBuy(new int[] { 84, 49, 5, 24, 70, 77, 87, 8 }, 3));
            Console.ReadKey();
        }
    }
    public class MyCircularDeque
    {
        private List<int> m_Data = new List<int>();
        private int m_Limit = 0;
        public MyCircularDeque(int k)
        {
            m_Limit = k;
        }

        public bool InsertFront(int value)
        {
            if (!IsFull())
            {
                m_Data.Insert(0, value);
                return true;
            }
            return false;
        }

        public bool InsertLast(int value)
        {
            if (!IsFull())
            {
                m_Data.Add(value);
                return true;
            }
            return false;
        }

        public bool DeleteFront()
        {
            if (!IsEmpty())
            {
                m_Data.RemoveAt(0);
                return true;
            }
            return false;

        }

        public bool DeleteLast()
        {
            if (!IsEmpty())
            {
                m_Data.RemoveAt(m_Data.Count - 1);
                return true;
            }
            return false;
        }

        public int GetFront()
        {
            if (!IsEmpty())
            {
                int res = m_Data[0];
                return res;
            }
            return -1;
        }

        public int GetRear()
        {
            if (!IsEmpty())
            {
                int res = m_Data[m_Data.Count-1];
                return res;
            }
            return -1;
        }

        public bool IsEmpty()
        {
            return m_Data.Count == 0 ? true : false;
        }

        public bool IsFull()
        {
            return m_Data.Count >= m_Limit ? true : false;
        }
    }
}
